package com.org.gsc.zuixindemo;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import moe.feng.common.stepperview.IStepperAdapter;
import moe.feng.common.stepperview.VerticalStepperItemView;
import moe.feng.common.stepperview.VerticalStepperView;
/**
 * Created by qundui on 2017/10/23.
 */
public class Stepview2 extends AppCompatActivity implements IStepperAdapter {
    private VerticalStepperView  mVerticalStepperView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.stepviewtest2);
       mVerticalStepperView= (VerticalStepperView) findViewById(R.id.vertical_stepper_view);
        mVerticalStepperView.setStepperAdapter(this);
    }
    @NonNull
    @Override
    public CharSequence getTitle(int index) {
        return "Step " + index;
    }
    @Nullable
    @Override
    public CharSequence getSummary(int index) {
        return "你是傻逼";
    }

    @Override
    public int size() {
        return 3;
    }

    @Override
    public View onCreateCustomView(final int index, Context context, VerticalStepperItemView parent) {
        View inflateView= LayoutInflater.from(context).inflate(R.layout.itemapater,parent,false);
        TextView contentView = inflateView.findViewById(R.id.item_content);
        contentView.setText(
                index == 0 ? "第一步!" : (index == 1 ? "第二部" : "第三部")
        );
        Button nextButton = inflateView.findViewById(R.id.button_next);
        nextButton.setText(index == size() - 1 ? "Set error text" : getString(android.R.string.ok));
        nextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!mVerticalStepperView.nextStep()) {
                    mVerticalStepperView.setErrorText(0, mVerticalStepperView.getErrorText(0) == null ? "Test error" : null);

                }
            }
        });
        Button prevButton = inflateView.findViewById(R.id.button_prev);
        prevButton.setText(index == 0 ? R.string.toggle_animation_button:android.R.string.cancel);
        inflateView.findViewById(R.id.button_prev).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (index != 0) {
                    mVerticalStepperView.prevStep();
                } else {
                    mVerticalStepperView.setAnimationEnabled(!mVerticalStepperView.isAnimationEnabled());
                }
            }
        });
        return inflateView;
    }

    @Override
    public void onShow(int index) {

    }
    @Override
    public void onHide(int index) {

    }
}
